package yxy.cherry.battle;

import yxy.cherry.battle.module.Position;
import yxy.cherry.battle.module.affix.Buff;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/** 队伍 */
public class Team {

	public Team() {
	}

	Map<Position, Fighter> fighters = new HashMap<>();
	NiuBee 神兵;
	Pokemon pokemon ;

	//兵符坑位的增减伤列表，key编码方式 国家_增减伤（0为增，1为减）,value为万分数的增减伤，不带符号
	HashMap<String,Double> commanderSeal = new HashMap<>();

	Team team对手;

	public void addFighterInPosition(Fighter fighter, Position position) {
		fighters.put(position, fighter);
		fighter.setTeam(this);
	}

	public Collection<Fighter> getFighters() {
		return fighters.values();
	}

	public Collection<Fighter> get活人() {
		ArrayList<Fighter> list = new ArrayList<>();
		for (Fighter fighter : getFighters()) {
			if (fighter.is活着()) {
				list.add(fighter);
			}
		}
		return list;
	}

	/**
	 * 获取队伍中死人列表
	 * @return
	 */
	public Collection<Fighter> getDieList() {
		ArrayList<Fighter> list = new ArrayList<>();
		for (Fighter fighter : getFighters()) {
			if (!fighter.is活着()) {
				list.add(fighter);
			}
		}
		return list;
	}

	/**
	 * 获得带指定buff的活玩家集合
	 * @param buffStateType
	 * @return
	 */
	public Collection<Fighter> getLiveAppendSpecialBuff(int buffStateType) {
		ArrayList<Fighter> list = new ArrayList<>();
		for (Fighter fighter : getFighters()) {
			if (fighter.is活着()) {
				for(Buff buff: fighter.getBuffMap().values()){
					if(buff.getBuffStateType() == Buff.BuffStateType.forNumber(buffStateType)){
						list.add(fighter);
						break;
					}
				}
			}
		}
		return list;
	}

	public Fighter getFighterByPosition(Position position) {
		return fighters.get(position);
	}

	public void setTeam对手(Team team对手) {
		this.team对手 = team对手;
	}

	public Team getTeam对手() {
		return team对手;
	}

	public boolean is有活口() {
		for (Fighter fighter : fighters.values()) {
			if (fighter.is活着()) {
				return true;
			}
		}
		return false;
	}

	public NiuBee get神兵() {
		return 神兵;
	}

	public void set神兵(NiuBee 神兵) {
		this.神兵 = 神兵;
	}

	public Pokemon getPokemon() {
		return pokemon;
	}

	public void setPokemon(yxy.cherry.battle.Pokemon pokemon) {
		this.pokemon = pokemon;
	}


	public double getBattlePower() {
		double power = 0;
		for (Fighter fighter : getFighters()) {
			power += fighter.getBattlePower();
		}
		return power;
	}

	public HashMap<String, Double> getCommanderSeal() {
		return commanderSeal;
	}

	public void setCommanderSeal(HashMap<String, Double> commanderSeal) {
		this.commanderSeal = commanderSeal;
	}
}
